package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/wending/h5/config"
	"net/http"
	"net/url"
)

type SiteListApiService service

type SiteListRequest struct {
	ctx        context.Context
	ApiService *SiteListApiService
}

type SiteListResponse struct {
	Code    *int64          `json:"code,omitempty"`
	Message *string         `json:"message,omitempty"`
	Data    *[]SiteListData `json:"data,omitempty"`
}

type SiteListData struct {
	MpId     *uint           `json:"mpId,omitempty"`
	MpName   *string         `json:"mpName,omitempty"`
	AppID    *string         `json:"appID,omitempty"`
	SiteList []*SiteListItem `json:"siteList,omitempty"`
}

type SiteListItem struct {
	Id     *uint64 `json:"id,omitempty"`
	Name   *string `json:"name,omitempty"`
	Domain *string `json:"domain,omitempty"`
}

func (r *SiteListRequest) Execute() (*SiteListResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *SiteListRequest) ConsumerKey(ConsumerKey string) *SiteListRequest {
	r.ctx = context.WithValue(r.ctx, config.ConsumerKey, ConsumerKey)
	return r
}

func (r *SiteListRequest) SecretKey(SecretKey string) *SiteListRequest {
	r.ctx = context.WithValue(r.ctx, config.SecretKey, SecretKey)
	return r
}

func (r *SiteListRequest) WithLog(enable bool) *SiteListRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *SiteListApiService) Get(ctx context.Context) *SiteListRequest {
	return &SiteListRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *SiteListApiService) getExecute(r *SiteListRequest) (*SiteListResponse, *http.Response, error) {

	cfg := a.client.Cfg
	var (
		localVarPath         = cfg.GetBasePath() + "/dist-api/siteList"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *SiteListResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
